package vip.geeker.iotms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.geeker.iotms.dto.DataSplitRuleDto;
import vip.geeker.iotms.help.Response;
import vip.geeker.iotms.persistance.mapper.DataSplitRuleMapper;
import vip.geeker.iotms.persistance.model.DataSplitRule;
import vip.geeker.iotms.service.IDataSplitRuleService;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author ChenKuoJun
 * date 2020-07-12
 */
@Service
@Transactional
public class DataSplitRuleService extends ServiceImpl<DataSplitRuleMapper, DataSplitRule> implements IDataSplitRuleService {
    @Resource
    private DataSplitRuleMapper dataSplitRuleMapper;

    public Response<PageInfo> queryPageInfoList(DataSplitRule dataSplitRule) {
        PageHelper.startPage(dataSplitRule.getPageNo(), dataSplitRule.getPageSz());
        List<DataSplitRuleDto > list = dataSplitRuleMapper.queryPageInfoList(dataSplitRule);

        PageInfo page = new PageInfo(list);
        return new Response<>(page);
    }

    public Boolean addRuleSplitRule(DataSplitRule dataSplitRule) {
        return dataSplitRuleMapper.insertSelective(dataSplitRule) > 0;
    }

    public Boolean updateByPrimaryKeySelective(DataSplitRule dataSplitRule) {
        return dataSplitRuleMapper.updateByPrimaryKeySelective(dataSplitRule) > 0;
    }

    public DataSplitRule queryById(Integer id) {
        DataSplitRule dataSplitRule = dataSplitRuleMapper.selectByPrimaryKey(id);
        return dataSplitRule;
    }
}
